/*
 * @Author: 霍格沃兹测试开发学社
 * @Desc: '更多测试开发技术探讨，请访问：https://ceshiren.com/t/topic/15860'
 */

package com.ceshiren.aitestmini.controller;


import com.ceshiren.aitestmini.dto.UserDto;
import com.ceshiren.aitestmini.dto.UserXmlDto;
import com.ceshiren.aitestmini.service.IUserService;
import com.ceshiren.aitestmini.service.UserService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/ceshiren")
public class BasePostController {

    @Autowired
    @Qualifier("userp")
//    UserService userp;
    UserService userService;
    //
//    UserService userService= new UserServiceImpl();
    @Autowired(required=false)
//    UserService userp;
            IUserService IuserService;



    @PostMapping(value = "/login",produces = "application/json")
    String login(@RequestBody UserDto userDto){


//        String login(String username,String password){
/*        if(userDto.getUsername().equals("gaigai") && userDto.getPassword().equals("ceshiren.com")){
            return "用户登录成功！用户名：{"+userDto.getUsername()+"}，密码为：{"+userDto.getPassword()+"}";

        }else {
            return "用户登录失败！用户名：{"+userDto.getUsername()+"}，密码为：{"+userDto.getPassword()+"}";

        }*/

//        return userp.login(userDto);

        return userService.login(userDto);
    }
//http://localhost:8080/{module}/register?desc={desc}&age={age}

    @PostMapping(value = "/{module}/register",produces = "application/json")
    @ApiOperation("post请求参数说明")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "module", value = "模块名称"),
            @ApiImplicitParam(name = "desc",value = "解释说明"),
            @ApiImplicitParam(name = "age",value = "年龄")
    })
    String registerAndParam(@RequestBody UserDto userDto, @PathVariable String module,
                            @RequestParam String desc,@RequestParam String age){
        return userDto.getUsername()+"注册成功！密码是："+userDto.getPassword()+"\n注册模块为："+module
                +"\n对应年龄："+age+"\n其它描述为："+desc;
    }

    @PostMapping(value = "/{module}/registerxml",produces = MediaType.APPLICATION_ATOM_XML_VALUE)
    String registerWithXMLAndParam(@RequestBody UserXmlDto userDto, @PathVariable String module,
                                   @RequestParam String desc, @RequestParam String age){
        return userDto.getUname()+"注册成功！密码是："+userDto.getPwd()+"\n注册模块为："+module
                +"\n对应年龄："+age+"\n其它描述为："+desc;
    }

}
